package com.longcai.piaojia.conn;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/9/2.
 */
@HttpInlet(Conn.USERADDRESS_INDEX_RESS)
public class UserAddressShowGet extends BaseAsyGet<UserAddressShowGet.UserAddressListEntity> {

    public String user_id;

    public UserAddressShowGet(AsyCallBack<UserAddressListEntity> asyCallBack) {
        super(asyCallBack);
    }

    @Override
    protected UserAddressListEntity parser(JSONObject object) throws Exception {

        TOAST = object.optString("message");

        if (object.optInt("code") == 200) {

            JSONArray array = object.optJSONArray("data");

            UserAddressListEntity userAddressListEntity = new UserAddressListEntity();

            for (int i = 0; i < array.length(); i++) {

                JSONObject o = array.optJSONObject(i);

                UserAddressEntity userAddressEntity = new UserAddressEntity();

                userAddressEntity.id = o.optString("id");
                userAddressEntity.user_id = o.optString("user_id");
                userAddressEntity.name = o.optString("name");
                userAddressEntity.phone = o.optString("phone");
                userAddressEntity.region_id = o.optString("region_id");
                userAddressEntity.address = o.optString("address");
                userAddressEntity.idnumber = o.optString("idnumber");
                userAddressEntity.status = o.optString("status");
                userAddressEntity.city = o.optString("city");

                userAddressListEntity.userAddressEntityList.add(userAddressEntity);

            }


            return userAddressListEntity;
        }


        return null;
    }



    public class UserAddressListEntity implements Serializable {

        public List<UserAddressEntity> userAddressEntityList = new ArrayList<>();

    }

    public static class UserAddressEntity implements Serializable {

        public String id, user_id, name, phone, region_id, address, idnumber, status, city;

    }


}
